import Quill from 'quill';
Quill.debug("error")
declare type Module = {
    name: string;
    module: any;
    options?: object;
};
const ImageBase = Quill.import('formats/image');
const ATTRIBUTES = [
    'alt',
    'height',
    'width',
    'style' // This is the added difference that needs to be saved properly
]
class CustomImage extends ImageBase {
    declare domNode: any; // Needed declaration for Typescript

    static formats(domNode: any) {
        return ATTRIBUTES.reduce((formats, attribute) => {
            const copy: any = {...formats};

            if (domNode.hasAttribute(attribute)) {
                copy[attribute] = domNode.getAttribute(attribute);
            }

            return copy;
        }, {});
    }

    format(name: any, value: any) {
        if (ATTRIBUTES.indexOf(name) > -1) {
            if (value) {
                this.domNode.setAttribute(name, value);
            } else {
                this.domNode.removeAttribute(name);
            }
        } else {
            super.format(name, value);
        }
    }
}

Quill.register('formats/image', CustomImage);
export {Quill}

import ImageUploader from "quill-image-uploader"
import {Server} from '@/stores/ajax';
export const ImageUploaderMoudel =
{
    name: 'imageUploader',
    module: ImageUploader,
    options: {
        upload: (file: any) => {
            let data = {
                image: file
            }
            return new Promise((resolue, reject) => {
                Server.axios.post("/file/upload_image", data, {
                    headers: {
                        'Content-Type': 'multipart/form-data'
                    }
                }).then((res) => {
                    Server.checkShowMessage(res)
                    if (res.data.code == 0) {
                        resolue(Server.fileBaseURL + res.data.return)
                    } else {
                        reject("服务器错误")
                    }
                }).catch(reject)
                // console.log(file)
            })
        }
    }
}
import '@vueup/vue-quill/dist/vue-quill.snow.css';
import '@vueup/vue-quill/dist/vue-quill.bubble.css';
